package com.ice_col.recyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2015/10/8 0008.
 */
public class SampleAdapter extends RecyclerView.Adapter<MyViewHolder>{

    private LayoutInflater mInflater;
    private Context mContext;
    private List<String> mDatas;

    public SampleAdapter (Context context , List<String> datas){
        this.mDatas=datas;
        this.mContext=context;
        mInflater=LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View view=mInflater.inflate(R.layout.recyclerview_item,parent,false);
        MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;
    }


    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv.setText(mDatas.get(position));
    }
}

class MyViewHolder extends RecyclerView.ViewHolder{
     TextView tv;

    public MyViewHolder(View itemView) {
        super(itemView);
        tv=(TextView) itemView.findViewById(R.id.item_tv);
    }
}
